home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.05 May 88 / LSP PalFun Stuff / PalFun < prev    next >
Encoding:
Text File  |  1988-04-14  |  5.8 KB  |  268 lines  |  [TEXT/PJMM]

  1. {        PalFun by Steve Sheets 3/88    }
  2.  
  3. {        Palette Manager Sample Program designed for MacTutor.    }
  4. {        It demonstrate various Palette Animation effects.    }
  5.  
  6. PROGRAM PalFun;
  7.  
  8.     USES
  9.         ROM85, ColorQuickDraw, ColorWindowMgr, PaletteMgr, PickerIntf, PalFunGlobals, PalFunStuff;
  10.  
  11.  
  12. {******************** Main Portion Programs ********************}
  13.  
  14.     PROCEDURE crash;
  15.     BEGIN
  16.         ExitToShell;
  17.     END;
  18.  
  19. {Set Up the normal Mac Interface}
  20.     PROCEDURE SetUp;
  21.         VAR
  22.             count : integer;
  23.     BEGIN
  24. {Standard Mac Program setup}
  25.         InitGraf(@thePort);
  26.         InitFonts;
  27.         FlushEvents(everyEvent, 0);
  28.         InitWindows;
  29.         InitMenus;
  30.         TEInit;
  31.         InitDialogs(@crash);
  32.         InitCursor;
  33.  
  34.         FOR count := appleM TO menuCount DO
  35.             myMenus[count] := GetMenu(count);
  36.         AddResMenu(myMenus[appleM], 'DRVR');
  37.         FOR count := appleM TO menuCount DO
  38.             BEGIN
  39.                 moveHHi(handle(myMenus[count]));
  40.                 HLock(handle(myMenus[count]));
  41.             END;
  42.         FOR count := appleM TO menuCount DO
  43.             InsertMenu(myMenus[count], 0);
  44.         DrawMenuBar;
  45.  
  46.         WITH screenBits.bounds DO
  47.             SetRect(dragRect, 4, 24, right - 4, bottom - 4);
  48.         doneFlag := FALSE;
  49.  
  50.         FOR count := 1 TO numWindows DO
  51.             BEGIN
  52.                 MyWindow[count] := NIL;
  53.                 MyPalette[count] := NIL;
  54.             END;
  55.     END;
  56.  
  57. {Given a Window ID number, close Window/Palette}
  58.     PROCEDURE CloseIt (N : INTEGER);
  59.     BEGIN
  60.         IF (N > 0) AND (N <= numWindows) THEN
  61.             BEGIN
  62.                 IF MyPalette[N] <> NIL THEN
  63.                     DisposePalette(MyPalette[N]);
  64.                 MyPalette[N] := NIL;
  65.                 IF MyWindow[N] <> NIL THEN
  66.                     DisposeWindow(MyWindow[N]);
  67.                 MyWindow[N] := NIL;
  68.             END;
  69.     END;
  70.  
  71. {Gets the Front most Window ID number.}
  72.     FUNCTION GetWindowNum (W : WindowPtr) : INTEGER;
  73.         VAR
  74.             N, count : INTEGER;
  75.     BEGIN
  76.         IF W = NIL THEN
  77.             GetWindowNum := 0
  78.         ELSE
  79.             BEGIN
  80.                 N := 0;
  81.                 FOR count := 1 TO numWindows DO
  82.                     IF MyWindow[count] = W THEN
  83.                         N := count;
  84.                 GetWindowNum := N;
  85.             END;
  86.     END;
  87.  
  88. {Standard Handling of the Menu.  Selecting the Window Menu, bring that window}
  89. {    to the front and that's all (Palette Manager handles changing colors and}
  90. {    creating update).  Animate Menu animate the front window if it can.}
  91.     PROCEDURE DoCommand (mResult : LONGINT);
  92.         VAR
  93.             theItem : INTEGER;
  94.             theMenu : INTEGER;
  95.             name : Str255;
  96.             N : INTEGER;
  97.             dummy : Boolean;
  98.             tempPort : GrafPtr;
  99.     BEGIN
  100.         theItem := LoWord(mResult);
  101.         theMenu := HiWord(mResult);
  102.         CASE theMenu OF
  103.             appleM : 
  104.                 IF theItem = 1 THEN
  105.                     theItem := Alert(AlertID, NIL)
  106.                 ELSE
  107.                     BEGIN
  108.                         GetItem(myMenus[appleM], theItem, name);
  109.                         N := OpenDeskAcc(name);
  110.                     END;
  111.             fileM : 
  112.                 CASE theItem OF
  113.                     1 : 
  114.                         BEGIN
  115.                             GetPort(tempPort);
  116.                             SetPort(FrontWindow);
  117.                             CASE GetWindowNum(FrontWindow) OF
  118.                                 ballW : 
  119.                                     AnimBall;
  120.                                 shapeW : 
  121.                                     AnimShape;
  122.                                 rainbowW : 
  123.                                     AnimRainbow;
  124.                                 fadeW : 
  125.                                     AnimFade;
  126.                                 OTHERWISE
  127.                             END;
  128.                             SetPort(tempPort);
  129.                         END;
  130.                     2 : 
  131.                         CloseIt(GetWindowNum(FrontWindow));
  132.                     4 : 
  133.                         doneFlag := TRUE;
  134.                     OTHERWISE
  135.                 END;
  136.             editM : 
  137.                 dummy := SystemEdit(theItem - 1);
  138.             winM : 
  139.                 IF (theItem > 0) AND (theItem <= numWindows) THEN
  140.                     BEGIN
  141.                         IF MyWindow[theItem] = NIL THEN
  142.                             BEGIN
  143.                                 CASE theItem OF
  144.                                     redW : 
  145.                                         MakeRed;
  146.                                     greenW : 
  147.                                         MakeGreen;
  148.                                     blueW : 
  149.                                         MakeBlue;
  150.                                     ballW : 
  151.                                         MakeBall;
  152.                                     curW : 
  153.                                         MakeCur;
  154.                                     shapeW : 
  155.                                         MakeShape;
  156.                                     rainbowW : 
  157.                                         MakeRainbow;
  158.                                     fadeW : 
  159.                                         MakeFade;
  160.                                     OTHERWISE
  161.                                 END;
  162.                             END
  163.                         ELSE
  164.                             SelectWindow(MyWindow[theItem]);
  165.                     END;
  166.             OTHERWISE
  167.         END;
  168.         HiliteMenu(0);
  169.     END;
  170.  
  171. {Extremely Standard Main Program Loop.}
  172.     PROCEDURE DoMainLoop;
  173.         VAR
  174.             theChar : CHAR;
  175.             myEvent : EventRecord;
  176.             whichWindow : WindowPtr;
  177.             oldPort : GrafPtr;
  178.             dummy : boolean;
  179.     BEGIN
  180.         REPEAT
  181.             SystemTask;
  182.             IF GetNextEvent(everyEvent, myEvent) THEN
  183.                 CASE myEvent.what OF
  184.                     mouseDown : 
  185.                         CASE FindWindow(myEvent.where, whichWindow) OF
  186.                             inSysWindow : 
  187.                                 SystemClick(myEvent, whichWindow);
  188.                             inMenuBar : 
  189.                                 DoCommand(MenuSelect(myEvent.where));
  190.                             inGoAway : 
  191.                                 IF TrackGoAway(whichWindow, myEvent.where) THEN
  192.                                     CloseIt(GetWindowNum(whichWindow));
  193.                             inDrag : 
  194.                                 IF (FrontWindow <> whichWindow) THEN
  195.                                     SelectWindow(whichWindow)
  196.                                 ELSE
  197.                                     DragWindow(whichWindow, myEvent.where, dragRect);
  198.                             inContent : 
  199.                                 IF (FrontWindow <> whichWindow) THEN
  200.                                     SelectWindow(whichWindow);
  201.                             OTHERWISE
  202.                         END; {of mouseDown}
  203.                     keyDown, autoKey : 
  204.                         BEGIN
  205.                             theChar := CHR(BitAnd(myEvent.message, charCodeMask));
  206.                             IF BitAnd(myEvent.modifiers, cmdKey) <> 0 THEN
  207.                                 DoCommand(MenuKey(theChar));
  208.                         END;
  209.                     updateEvt : 
  210.                         BEGIN
  211.                             whichWindow := WindowPtr(myEvent.message);
  212.                             IF whichWindow <> NIL THEN
  213.                                 BEGIN
  214.                                     GetPort(oldPort);
  215.                                     SetPort(whichWindow);
  216.                                     BeginUpdate(whichWindow);
  217.                                     CASE GetWindowNum(whichWindow) OF
  218.                                         redW : 
  219.                                             DoRedUpdate;
  220.                                         greenW : 
  221.                                             DoGreenUpdate;
  222.                                         blueW : 
  223.                                             DoBlueUpdate;
  224.                                         curW : 
  225.                                             DoCurUpdate;
  226.                                         ballW : 
  227.                                             DoBallUpdate;
  228.                                         shapeW : 
  229.                                             DoShapeUpdate;
  230.                                         rainbowW : 
  231.                                             DoRainbowUpdate;
  232.                                         fadeW : 
  233.                                             DoFadeUpdate;
  234.                                         OTHERWISE
  235.                                     END;
  236.                                     EndUpdate(whichWindow);
  237.                                     SetPort(oldPort);
  238.                                 END;
  239.                         END;
  240.                     OTHERWISE
  241.                 END;
  242.         UNTIL doneFlag;
  243.     END;
  244.  
  245. {Dispose of all the Palettes and closes all the Windows.}
  246.     PROCEDURE CloseDown;
  247.         VAR
  248.             count : integer;
  249.     BEGIN
  250.         FOR count := 1 TO numWindows DO
  251.             CloseIt(count);
  252.         FOR count := appleM TO menuCount DO
  253.             BEGIN
  254.                 DeleteMenu(count);
  255.                 DisposeMenu(myMenus[count]);
  256.             END;
  257.         DrawMenuBar;
  258.     END;
  259.  
  260. {Main Body Program.  Setup, Do it, Close down.}
  261. BEGIN
  262.     IF ColorQDExists THEN
  263.         BEGIN
  264.             SetUp;
  265.             DoMainLoop;
  266.             CloseDown;
  267.         END;
  268. END.